/**
 * 내용 1. 데이터 송수신
 * 		2. 조건 분기 처리
 */

package jong;

import java.io.*;
import java.net.*;

public class MultiChatServerThread extends Thread {
	Socket socket = null;
	MultiChatServer server = null;
	SocketData sd = null;
	
	ObjectOutputStream send = null;
	ObjectInputStream receive = null;
	
	boolean tFlag = false;

	public MultiChatServerThread(MultiChatServer server, Socket socket) {
		this.server = server;
		this.socket = socket;
	}

	public void run(){
		try{
			send = new ObjectOutputStream(socket.getOutputStream());
			receive = new ObjectInputStream(socket.getInputStream());
			
			tFlag = true;
			while(tFlag){
				sd = (SocketData)receive.readObject();
				if(sd.getCommand().equals("login")){
					server.clients.put(sd.getUser(), this);
					server.dataSet("[" + socket.getInetAddress().getHostAddress() + "][" + sd.getUser() + "]" + sd.getMessage() );
				}else if(sd.getCommand().equals("logout")){
					server.clients.remove(sd.getUser());
				}
			}
			
		}catch(Exception ex) {ex.getMessage();}
	}
	
	public static void main(String[] args) {


	}

}
